<template xmlns:el-col="http://www.w3.org/1999/html">
  <el-dialog :title="title" v-model="props.open" width="800px" append-to-body style="min-height: 200px">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品标识" prop="productKey">
        <el-input
          v-model="queryParams.productKey"
          placeholder="请输入产品标识"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品状态" prop="enableFlag">
        <el-select v-model="queryParams.enableFlag" placeholder="请选择产品状态" style="width: 200px" clearable>
          <el-option label="开启" value="1" />
          <el-option label="关闭" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品标识" align="center" prop="productKey" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            link type="primary"
            icon="Check"
            @click="chooseProduct(scope.row)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>

<!--    <el-row>
      <el-col style="padding: 8px" :span="6" v-for="(item,index) in productInfoList" :key="index">
        <el-card style="max-width: 100%">
          <template #header>
            <div class="card-header" style="font-size: 25px;display: flex;align-items: center; ">
              <svg-icon icon-class="cube" style="width: 1em; height: 1em; margin-right: 8px" /> {{ item.productName }}
            </div>
          </template>
          <el-row>
            <el-col :span="18">
              <el-form label-width="78px">
                <el-form-item label="产品标识:" prop="productKey" style="margin-bottom: 0">
                  <span>{{ item.productKey }}</span>
                </el-form-item>
                <el-form-item label="产品状态:" prop="enableFlag" style="margin-bottom: 0">
                  <el-tag v-if="item.enableFlag === 1" type="success">开启</el-tag>
                  <el-tag v-else-if="item.enableFlag === 0" type="danger">关闭</el-tag>
                  <el-tag v-else type="info">未知</el-tag>
                </el-form-item>
                <el-form-item label="创建人:" prop="createBy" style="margin-bottom: 0">
                  <span>{{ item.createBy }}</span>
                </el-form-item>
                <el-form-item label="创建时间:" prop="createTime" style="margin-bottom: 0">
                  <span>{{ item.createTime }}</span>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="6" style="display:flex;align-items: center">
              <img style="width: 100px;height: 70px" :src="item.productPicture ? baseUrl+item.productPicture : defaultImg" alt="" />
            </el-col>
          </el-row>
          <template #footer>
            <el-row :gutter="15">
              <el-col :span="8">
                <el-button class="cu-btn" type="primary" icon="EditPen" plain @click="handleUpdate(item)">编辑</el-button>
              </el-col>
              <el-col :span="8">
                <el-button class="cu-btn" type="warning" icon="View" plain @click="handleView(item)">详情</el-button>
              </el-col>
              <el-col :span="8">
                <el-button type="danger" icon="Delete" @click="handleDelete(item)" plain>删除</el-button>
              </el-col>
            </el-row>
          </template>
        </el-card>
      </el-col>
    </el-row>-->

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="SelectProductInfo">
import { listProductInfo } from "@/api/manager/productInfo";

const { proxy } = getCurrentInstance();
const emit = defineEmits();

const props = defineProps({
  // 数据
  open: {
    type: Boolean,
    default: false,
  }
});

const productInfoList = ref([]);
const total = ref(0);
const loading = ref(true);
const showSearch = ref(true);
const title = ref("选择产品");


const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    productName: null,
    productKey: null,
    productConfig: null,
    productPicture: null,
    productLink: null,
    enableFlag: null,
    deleted: null,
  }
});

const { queryParams } = toRefs(data);

watch(
  () => props.open,
  (newVal, oldVal) => {
    if (props.open){
      getList()
    }
  }
)

/** 查询产品信息表列表 */
function getList() {
  loading.value = true;
  listProductInfo(queryParams.value).then(response => {
    productInfoList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
function chooseProduct(row){
  emit('setProductKey',row.productKey)
}
// 取消按钮
function cancel() {
  emit('closeProduct')
}

getList();
</script>
<style lang="scss" scoped>

</style>
